<h2>Search customers</h2>

<div class="form-search">
<%= render 'search' %>
</div>

<h2>Listing customers</h2>

<table class="scaffold-table">
	<tr>
		<th>NO.</th>
		<th>Code</th>
		<th>Title</th>
		<th>First name</th>
		<th>Last name</th>
		<th>Birth date</th>
		<th>Nick name</th>
		<th>Card type</th>
		<th>Card no</th>
		<th>Branch</th>
		<th>Black list</th>
		<th>View</th>
		<th>Edit</th>
		<th>Delete</th>
	</tr>

	<% @customers.each_with_index do |customer,index| %>
	<tr>
		<td><%= index+1 %></td>
		<td><%= customer.code %></td>
		<td><%= customer.title.name %></td>
		<td><%= customer.first_name %></td>
		<td><%= customer.last_name %></td>
		<td><%= customer.birth_date %></td>
		<td><%= customer.nick_name %></td>
		<td><%= customer.card.name %></td>
		<td><%= customer.card_no %></td>
		<td><%= customer.branch.code+":"+customer.branch.name %></td>
		<td><%= customer.black_list %></td>
		<td class="command"> <% if can? :read, Customer %>
		<%= link_to image_tag("view-icon.png", :border => 0) , customer  %>
		<% else %>
		-
		<% end %> </td>
		<td class="command"> <% if can? :update, Customer %>
		<%= link_to image_tag("edit-icon.png", :border => 0) , edit_customer_path(customer)  %>
		<% else %>
		-
		<% end %> </td>
		<td class="command"> <% if can? :destroy, Customer %>
		<%= link_to image_tag("delete-icon.png", :border => 0) , customer , :confirm => 'Are you sure?', :method => :delete %>
		<% else %>
		-
		<% end %> </td>
		
		
	</tr>
	<% end %>
</table>
<%= will_paginate @customers %>
<% if can? :create , Customer %>
<%= link_to image_tag("add-icon.png", :border => 0) , new_customer_path , {:class => 'form-command'} %>
<%= link_to 'New Customer', new_customer_path %>
<% end %> 
